﻿using AutoMapper;
using MediatR;
using T_Rbac_APi.Application.Command.DepartmentCommand;
using T_Rbac_Demain;
using T_Rbac_Rep.Interface;

namespace T_Rbac_APi.Application.CommandHandler.DepartmentHandler
{
    public class DepartmentUpdateHandlers : IRequestHandler<DepartmentUpdateCommand, int>
    {
        private readonly IMapper mapper;
        private readonly IDapartment dapartment;

        public DepartmentUpdateHandlers(IMapper mapper, IDapartment dapartment)
        {
            this.mapper = mapper;
            this.dapartment = dapartment;
        }

        public async Task<int> Handle(DepartmentUpdateCommand request, CancellationToken cancellationToken)
        {
            request.UpdateDate = DateTime.Now;
            request.UpdateBy = "小红";
            var list = mapper.Map<Dapartment>(request);
            return await dapartment.Update(list);
        }
    }
}
